window.addEventListener('load', function () {
    var tel = document.querySelector('#tel');
    var text = document.querySelector('#text');
    var password = document.querySelector('#password');
    var surePassword = document.querySelector('#surePassword');
    var regTel = /^1[3|4|5|7|8|9]\d{9}$/;
    var regText = /^\d{6}$/;
    var regPwd = /^[a-zA-Z0-9_-]{6,16}$/;
    regular(regTel, tel);
    regular(regText, text);
    regular(regPwd, password);

    function regular(reg, ele) {
        ele.addEventListener('blur', function () {
            if (reg.test(this.value)) {
                this.nextElementSibling.className = 'correct_style';
                this.nextElementSibling.innerHTML = '<i class="reg_form_iconCorrect"></i>格式输入正确';
            } else if (this.value == '') {
                this.nextElementSibling.className = '';
                this.nextElementSibling.innerHTML = '';
            } else {
                this.nextElementSibling.className = 'error_style';
                this.nextElementSibling.innerHTML = '<i class="reg_form_iconWrong"></i>格式不正确，请重新输入';
            }
        })
    }
    surePassword.addEventListener('blur', function () {
        if (this.value == password.value && !this.value == '') {
            this.nextElementSibling.className = 'correct_style';
            this.nextElementSibling.innerHTML = '<i class="reg_form_iconCorrect"></i>输入正确';
        } else if (this.value == '') {
            this.nextElementSibling.className = '';
            this.nextElementSibling.innerHTML = '';
        } else {
            this.nextElementSibling.className = 'error_style';
            this.nextElementSibling.innerHTML = '<i class="reg_form_iconWrong"></i>密码输入不正确';
        }

    })
})